<?php
namespace addon\mall\validate;
use app\common\validate\ValidateBase;
use think\Db;
class ShopConfig extends ValidateBase
{
    // 验证规则
    protected $rule = [
        'shop_name'                             => 'require',            
        'shop_desc'                             => 'require',      
        'market_price_ratio'                    => 'require|>=:1',     
        'integral_name'                         => 'require',   
        'integral_ratio'                        => 'require|>=:0', 
        'reg_in_integral'                       => 'require|>=:0',
        'default_stock'                         => 'require|number|>=:0|regex:\d{1,}',
        'max_upload_goods_photo'                => 'require|number|>=:1|regex:\d{1,}',
        'thumb_width'                           => 'require|number|>=:1',
        'thumb_height'                          => 'require|number|>=:1',
        'goods_img_width'                       => 'require|number|>=:1',
        'goods_img_height'                      => 'require|number|>=:1',
    ];

    // 验证提示
    protected $message = [
        'shop_name.require'                  => '商店标题不能为空',
        'shop_desc.require'                  => '商店描述不能为空',
        'market_price_ratio.egt'             => '市场价格比例不对',
        'integral_name.require'              => '消费积分名称不能为空',
        'integral_ratio.require'             => '积分换算比例不能为空',
        'integral_ratio.egt'                 => '积分换算比例必须>=0',
        'reg_in_integral.require'            => '会员注册赠送积分必须',
        'reg_in_integral.egt'                => '会员注册赠送积分必须>=0',
        'default_stock.number'               => '默认库存必须为数字',
        'default_stock.egt'                  => '默认库存必须>=0',
        'default_stock.regex'                => '默认库存必须为整数',
        'max_upload_goods_photo.require'     => '商品图片最大上传数必须>',
        'max_upload_goods_photo.egt'         => '商品图片最大上传数必须>=1',
        'max_upload_goods_photo.regex'       => '商品图片最大上传数必须是整数',
        'thumb_width.require'                => '缩略图宽度必须',
        'thumb_width.egt'                    => '缩略图宽度必须>=1',
        'thumb_width.number'                 => '缩略图宽度必须是整数',
        'thumb_height.require'               => '缩略图高度必须',
        'thumb_height.egt'                   => '缩略图高度必须>=1',
        'thumb_height.number'                => '缩略图高度必须是整数',
        'goods_img_width.require'            => '商品图片宽度必须',
        'goods_img_width.egt'                => '商品图片宽度必须>=1',
        'goods_img_width.number'             => '商品图片宽度必须是整数',
        'goods_img_height.require'           => '商品图片高度必须',
        'goods_img_height.egt'               => '商品图片高度必须>=1',
        'goods_img_height.number'            => '商品图片高度必须是整数',
    ];

    // 应用场景
    protected $scene = [
        'add'=>['shop_name','shop_desc','market_price_ratio','integral_name','integral_ratio','reg_in_integral','default_stock','thumb_width','thumb_height','goods_img_width','goods_img_height','max_upload_goods_photo'],
    ];
}